<template>
  <div>
    <el-form
      ref="ruleFormRef"
      style="max-width: 600px"
      :model="ruleForm"
      :rules="rules"
      label-width="auto"
      class="demo-ruleForm"
      :size="formSize"
      status-icon
    >
      <span style="text-align: left">基础信息</span>
      <br />
      <br />
      <el-row :gutter="24">
        <el-col :span="12" :offset="0">
          <el-form-item label="收入单号" prop="name">
            <el-input v-model="ruleForm.ReceiptNumber" />
          </el-form-item>
          <el-form-item label="收入类型" prop="ReceiptNumber">
            <el-select
              v-model="ruleForm.IncomeTypeId"
              placeholder="请选择"
              style="width: 240px"
            >
              <el-option
                v-for="item in IncomeTypeList"
                :key="item.IncomeTypeId"
                :label="item.IncomeTypeName"
                :value="item.IncomeTypeId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注" prop="Remark">
            <el-input v-model="ruleForm.Remark" type="textarea" />
          </el-form-item>
        </el-col>
        <el-col :span="12" :offset="0">
          <el-form-item label="收入主题" prop="IncomeTheme">
            <el-input v-model="ruleForm.IncomeTheme" />
          </el-form-item>
          <el-form-item label="收入日期" prop="IncomeDate">
            <el-date-picker
              v-model="ruleForm.IncomeDate"
              type="date"
              label="Pick a date"
              placeholder="Pick a date"
              style="width: 100%"
            />
          </el-form-item>
          <el-form-item label="收入金额" prop="IncomePrice">
            <el-input v-model="ruleForm.IncomePrice" /> </el-form-item
        ></el-col>
      </el-row>
      <span style="text-align: left">付款方信息</span>
      <br />
      <br />
      <el-row :gutter="24">
        <el-col :span="12" :offset="0">
          <el-form-item label="付款方" prop="Payer">
            <el-input v-model="ruleForm.Payer" />
          </el-form-item>
          <el-form-item label="账户名称" prop="AccountTitle">
            <el-input v-model="ruleForm.AccountTitle" />
          </el-form-item>
          <el-form-item label="网点名称" prop="NetworkName">
            <el-input v-model="ruleForm.NetworkName" /> </el-form-item
        ></el-col>
        <el-col :span="12" :offset="0">
          <el-form-item label="开户银行" prop="DepositBank">
            <el-input v-model="ruleForm.DepositBank" />
          </el-form-item>
          <el-form-item label="银行账号" prop="BankAccount">
            <el-input v-model="ruleForm.BankAccount" /> </el-form-item
        ></el-col>
      </el-row>
      <!-- <span style="text-align: left">销售订单</span>
      <br />
      <br />
      <el-row :gutter="24">
        <el-col :span="12" :offset="0">
          <el-form-item label="销售订单主题" prop="name">
            <el-input v-model="ruleForm.name" />
          </el-form-item>
          <el-form-item label="出库状态" prop="name">
            <el-input v-model="ruleForm.name" />
          </el-form-item>
          <el-form-item label="已收款金额" prop="name">
            <el-input v-model="ruleForm.name" /> </el-form-item
        ></el-col>
        <el-col :span="12" :offset="0">
          <el-form-item label="销售日期" prop="name">
            <el-input v-model="ruleForm.name" />
          </el-form-item>
          <el-form-item label="优惠后金额" prop="name">
            <el-input v-model="ruleForm.name" /> </el-form-item
        ></el-col>
      </el-row> -->
      <span style="text-align: left">附件</span>
      <br />
      <br />
      <el-upload
        class="avatar-uploader"
        action="http://localhost:5055/api/Sale/GetImage"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
      >
        <img
          v-if="ruleForm.IncomeStatementImage"
          :src="ruleForm.IncomeStatementImage"
          class="avatar"
          prop="IncomeStatementImage"
        />
        <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
      </el-upload>
      <br />
      <br />
      <br />
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button>关闭</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script lang="ts" setup>
import { onMounted, reactive, ref } from "vue";
import { ElMessage, FormInstance, FormRules, ElUpload } from "element-plus";
import axios from "axios";
import { UploadFilled } from "@element-plus/icons-vue";
import { Plus } from "@element-plus/icons-vue";
import type { UploadProps } from "element-plus";
import { useRouter, useRoute } from "vue-router";
const Router = useRouter();
const handleAvatarSuccess: UploadProps["onSuccess"] = (response) => {
  ruleForm.IncomeStatementImage = response;
};

interface RuleForm {
  ReceiptNumber: string;
  Remark: string;
  IncomeTypeId: string;
  IncomeTheme: string;
  IncomeDate: string;
  IncomePrice: string;
  Payer: string;
  AccountTitle: string;
  NetworkName: string;
  DepositBank: string;
  BankAccount: string;
  IncomeStatementImage: string;
}

const formSize = ref("default");
const ruleFormRef = ref<FormInstance>();
const ruleForm = reactive<RuleForm>({
  ReceiptNumber: "",
  Remark: "",
  IncomeTypeId: "",
  IncomeTheme: "",
  IncomeDate: "",
  IncomePrice: "",
  Payer: "",
  AccountTitle: "",
  NetworkName: "",
  DepositBank: "",
  BankAccount: "",
  IncomeStatementImage: "",
});

const rules = reactive<FormRules<RuleForm>>({
  // name: [
  //   { required: true, message: "Please input Activity name", trigger: "blur" },
  //   { min: 3, max: 5, message: "Length should be 3 to 5", trigger: "blur" },
  // ],
  // region: [
  //   {
  //     required: true,
  //     message: "Please select Activity zone",
  //     trigger: "change",
  //   },
  // ],
  // count: [
  //   {
  //     required: true,
  //     message: "Please select Activity count",
  //     trigger: "change",
  //   },
  // ],
  // date1: [
  //   {
  //     type: "date",
  //     required: true,
  //     message: "Please pick a date",
  //     trigger: "change",
  //   },
  // ],
  // date2: [
  //   {
  //     type: "date",
  //     required: true,
  //     message: "Please pick a time",
  //     trigger: "change",
  //   },
  // ],
  // type: [
  //   {
  //     type: "array",
  //     required: true,
  //     message: "Please select at least one activity type",
  //     trigger: "change",
  //   },
  // ],
  // resource: [
  //   {
  //     required: true,
  //     message: "Please select activity resource",
  //     trigger: "change",
  //   },
  // ],
  // desc: [
  //   { required: true, message: "Please input activity form", trigger: "blur" },
  // ],
});

const submitForm = () => {
  axios.post("InconeStatementDTO/AddIncomeState", ruleForm).then((res) => {
    if (res.data > 0) {
      ElMessage.success("添加成功！");
      Router.push("/UserList/incomeshow");
    }
  });
};

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  formEl.resetFields();
};
const IncomeTypeList = ref([]);
const GetIncomeTypeList = () => {
  axios.get("InconeStatementDTO/GetIncomeType").then((res) => {
    IncomeTypeList.value = res.data;
  });
};
const options = Array.from({ length: 10000 }).map((_, idx) => ({
  value: `${idx + 1}`,
  label: `${idx + 1}`,
}));
GetIncomeTypeList();
</script>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  text-align: center;
}
</style>
<style scoped>
.avatar-uploader .avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
